# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : draft.py
# @Time     : 2024/4/7 23:45
# @Author   : Robot-Zsj
"""
description:

input
5
100 200 300 400 500
3 4
3 5
1 3
1 2

output
700
"""

n = int(input())

wealth = list(map(int, input().split()))
wealth.insert(0, 0)

family = []
family.extend(wealth)

for _ in range(n - 1):
    fa, ch = map(int, input().split())
    family[fa] += wealth[ch]

print(max(family))
